package com.fenghuajueli.libbasecoreui.manager;

import com.fenghuajueli.lib_data.entity.db.MattersDbEntity;
import com.fenghuajueli.lib_data.entity.db.MattersDbEntityDao;
import com.fenghuajueli.lib_data.entity.db.TargetDbEntity;
import com.fenghuajueli.lib_data.entity.db.TargetDbEntityDao;
import com.fenghuajueli.libbasecoreui.BaseApplication;

import java.util.List;

public class TargetManager {

    private static class MattersManagerSingleton {
        private static final TargetManager INSTANCE = new TargetManager();

    }

    public static TargetManager getInstance() {
        return TargetManager.MattersManagerSingleton.INSTANCE;
    }

    private TargetManager() {
    }


    public void saveTargetDbEntity(TargetDbEntity targetDbEntity) {
        BaseApplication.getTargetDaoMaster().newSession().getTargetDbEntityDao().insertOrReplace(targetDbEntity);
    }

    public List<TargetDbEntity> getTargetAllData() {
        List<TargetDbEntity> list = BaseApplication.getTargetDaoMaster().newSession().getTargetDbEntityDao().queryBuilder().list();
        return list;
    }

    public List<TargetDbEntity> getTargetStateData(int state) {
        List<TargetDbEntity> list = BaseApplication.getTargetDaoMaster().newSession().getTargetDbEntityDao().queryBuilder()
                .where(TargetDbEntityDao.Properties.State.eq(state)).list();
        return list;
    }

    public List<TargetDbEntity> getTargetData(long createTime) {
        List<TargetDbEntity> list = BaseApplication.getTargetDaoMaster().newSession().getTargetDbEntityDao().queryBuilder()
                .where(TargetDbEntityDao.Properties.Create_time.eq(createTime)).list();
        return list;
    }

    public List<TargetDbEntity> deleteTarget(TargetDbEntity targetDbEntity) {
        List<TargetDbEntity> list = BaseApplication.getTargetDaoMaster().newSession().getTargetDbEntityDao().queryBuilder()
                .where(TargetDbEntityDao.Properties.Create_time.eq(targetDbEntity.getCreate_time())).list();
        if (list != null && list.size() > 0) {
            BaseApplication.getTargetDaoMaster().newSession().getTargetDbEntityDao().deleteInTx(list);
        }
        return getTargetAllData();
    }

    public List<TargetDbEntity> updateTargetDbEntity(TargetDbEntity targetDbEntity) {
        BaseApplication.getTargetDaoMaster().newSession().getTargetDbEntityDao().updateInTx(targetDbEntity);

        return getTargetAllData();
        /*List<MattersDbEntity> list = BaseApplication.getMattersDaoMaster().newSession().getMattersDbEntityDao()
                .queryBuilder().where(MattersDbEntityDao.Properties.Create_time.eq(mattersDbEntity.getCreate_time())).list();
        if (list != null && list.size() > 0) {
        }*/
    }

}
